package components.utils
{

    public class LabelItemUtil
    {
        public static function hasLabel(v:Object):Boolean
        {
            if (v != null && (v.hasOwnProperty("label") || v.hasOwnProperty("@label")))
                return true;

            return false;
        }

        public static function getLabel(v:Object):String
        {
            if (hasLabel(v))
            {
                if (v is XML)
                    return v.@label;
                else
                    return v["label"];
            }

            if (v is XML)
                return XML(v).toXMLString();
            else
            {
                if (v == null)
                    return "";
                else
                    return String(v);
            }

        }

        public static function hasName(v:Object):Boolean
        {
            if (v != null && v.hasOwnProperty("name"))
                return true;

            return false;
        }

        public static function getName(v:Object):String
        {
            if (hasName(v))
                return v["name"];

            if (v == null)
                return "";
            else
                return String(v);
        }
    }
}